//vim: sw=4:ts=4:nu:nospell:fdc=4
/**
 * Simple Viewport Example
 *
 * @author Ing. Jozef Sakáloš
 * @copyright (c) 2008, by Ing. Jozef Sakáloš
 * @date 12. April 2008
 * @version $Id: simplevp.js 17 2008-04-24 14:57:16Z jozo $
 *
 * @license simplevp.js is licensed under the terms of the Open Source
 * LGPL 3.0 license. Commercial use is permitted to the extent that the
 * code/component(s) do NOT become part of another Open Source or Commercially
 * licensed development library or toolkit without explicit permission.
 *
 * License details: http://www.gnu.org/licenses/lgpl.html
 */

/*global Ext */



var workflow;
var carElements;
var viewport;
var figure;
var figures;
var selectedNode;
var roleToEdit;

Ext.onReady(function() {
	Ext.Ajax.request({
		url: 'configure/session.action',
		success: function(response,options) 
		{ 
			var tab  = tabPanel.getActiveTab();
			var responseText = response.responseText;
			var array=responseText.split(",");
			var array2=array[2].split(":");
			tab.setTitle(array2[1]);
		},
		params: { id: '' },
		failure: function(response,options) 
		{ 
			var west = Ext.getCmp('west-panel');
			west.getEl().mask();
			var east = Ext.getCmp('east-panel');
			east.getEl().mask();
			var south = Ext.getCmp('south-panel');
			south.getEl().mask();
			var center = Ext.getCmp('center-panel');
			center.getEl().mask();
		}
	});

	workflow  = new Workflow("center1");
	Ext.QuickTips.init();

	Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));

	//////////////////////////////////////////////////////////////////////////////////
	/*                         START  -  FORMS                                      */
	/*                                                                              */
	/*                                                                              */
	//////////////////////////////////////////////////////////////////////////////////


	var newUoLForm = new Ext.FormPanel({
		xtype:'form'
		,id:'uol-form'
		,defaultType:'textfield'
		,frame:true
		,method:'post'
		,url:'uol/createUoL.action'
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'title'
			,name:'title'
		},{
			xtype      : 'textareafield'
			,id        :'subject'
			,grow      : true
			,name      : 'subject'
			,fieldLabel: 'Subject'
			,anchor    : '100%'
		},{
			xtype      : 'textareafield'
			,id        :'description'
			,grow      : true
			,name      : 'description'
			,fieldLabel: 'Description'
			,anchor    : '100%'
			}]
		,buttonAlign:'right'
		,buttons:[
		          {text:'Cancel',
		        	  handler:function() {
		        		  newUoLWin.hide();
		        	  }},
		        	  {text:'Create' ,
		        		  handler:function() {
		        			  Ext.getCmp('uol-form').getForm().submit(
		        					  {params:{cmd:'submit'},
		        						  waitMsg: 'Creation of Learning Design...',
		        						  success: function(response) 
		        						  { 
		        							  var tab  = tabPanel.getActiveTab();
		        							  var title = response._fields.items[0].lastValue;
		        							  tab.setTitle(title);
		        							  newUoLWin.hide();
		        							  newUoLForm.getForm().reset();
		        							  var west = Ext.getCmp('west-panel');
		        							  west.getEl().unmask();
		        							  var east = Ext.getCmp('east-panel');
		        							  east.getEl().unmask();
		        							  var south = Ext.getCmp('south-panel');
		        							  south.getEl().unmask();
		        							  var center = Ext.getCmp('center-panel');
		        							  center.getEl().unmask();
		        						  }
		        					  ,
		        					  failure: function(form, action) {
		        						  Ext.Msg.alert('Error', 'Failed creating new Learning Design'); 
		        						  newUoLWin.hide();
		        					  }
		        					  });
		        		  }
		        	  }	        	   
		        ]
	});

	var RoleAttributeForm = new Ext.FormPanel({
		xtype:'form'
		,id:'roleAttribute-form'
		,defaultType:'textfield'
		,frame:true
		,url: "role/saveAttributes.action"
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'text'
			,name:'text'
			,readOnly : true
		},{
			xtype: 'fieldset',
			title: 'Attributes',
			collapsible: true,
			defaultType: 'textfield',
			layout: 'anchor',
			defaults: {
				anchor: 'right',
				labelWidth: 300
			},
			items: [{
				xtype: 'radiofield',
				name: 'allowCreation',
				id: 'rb1',
				fieldLabel: 'Allow creation of multiple occurences during runtime',
				aling: 'right',
				boxLabel: 'Yes',
				inputValue: 'true'
			},{
				xtype: 'radiofield',
				name: 'allowCreation',
				id: 'rb2',
				fieldLabel: '',
				aling: 'right',
				labelSeparator: '',
				hideEmptyLabel: false,
				boxLabel: 'No',
				inputValue: 'false'
			},{
				xtype: 'radiofield',
				name: 'notAssignToOther',
				id: 'rb3',
				fieldLabel: 'Person assigned to this role may not be assigned to any other role',
				aling: 'right',
				boxLabel: 'Yes',
				inputValue: 'true'
			},{
				xtype: 'radiofield',
				name: 'notAssignToOther',
				id: 'rb4',
				fieldLabel: '',
				aling: 'right',
				labelSeparator: '',
				hideEmptyLabel: false,
				boxLabel: 'No',
				inputValue: 'false'
			},{
				fieldLabel:'Minimun number of Persons'
				,id:'minPersons'
				,name:'minPersons'
				,value: 'minPersons'
			},{
				fieldLabel:'Maximun number of Persons'
				,id:'maxPersons'
				,name:'maxPersons'
				,value: 'maxPersons'
			}]
			},{
				xtype: 'htmleditor',
				name: 'information',
				id: 'information',
				fieldLabel: 'Addition Information',
				height: 200,
				anchor: '100%'
			}]
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  newRoleAttributeWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('roleAttribute-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Role Attributes...',
				       						  success: function(response) 
				       						  { 
				       							  newRoleAttributeWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing role'); 
					        					  newRoleAttributeWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				});



	var newStaffRole = new Ext.FormPanel({ 
		labelWidth:80,
		url:'role/staff.action', 
		id:'StaffRole-form',
		frame:true, 
		//title:'Create new Role', 
		defaultType:'textfield',

		items:[{ 
			fieldLabel:'Role', 
			name:'role', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newStaffRoleWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('StaffRole-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of Staff Role...',
							success: function(response) 
							{ 
								newStaffRole.getForm().reset();
								newStaffRoleWin.hide();
								Ext.getCmp('rolesTreeId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Staff Role Or Role title already exists'); 
							newStaffRoleWin.hide();
						}
						});
			}
		}] 
	});

	var newLearnerRole = new Ext.FormPanel({ 
		labelWidth:80,
		url:'role/learner.action', 
		id: 'LearnerRole-form',
		frame:true, 
		defaultType:'textfield',
		items:[{ 
			fieldLabel:'Role', 
			name:'role', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newLearnerRoleWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('LearnerRole-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of new Learner Role...',
							success: function(response, rolesTree) 
							{ 
								newLearnerRole.getForm().reset();
								newLearnerRoleWin.hide();
								Ext.getCmp('rolesTreeId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Learner Role Or Role title already exists'); 
							newLearnerRoleWin.hide();
						}
						});
			}
		}] 
	});

	var learningActivityForm = new Ext.FormPanel({
		id:'learningActivityAttribute-form'
		,frame:true
		,width:400
		,height:250
		,url: "role/saveLearningActivityAttributes.action"
			,items:[{
					defaults:{layout:'fit'}
					,xtype:'tabpanel'
					,items:[{
							title:'Activity Description',
							xtype: 'htmleditor',
							name: 'activitydecription',
							id: 'activitydecription',
							height: 200,
							anchor: '100%'
							},{
							title:'Add-ons'
							}]
					}]
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  learningActivityWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('learningActivityAttribute-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Role Attributes...',
				       						  success: function(response) 
				       						  { 
				       							learningActivityWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing role'); 
					        					  learningActivityWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				});

	//////////////////////////////////////////////////////////////////////////////////
	/*                         END  -  FORMS                                        */
	/*                                                                              */
	/*                                                                              */
	//////////////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////////////
	/*                         START  -  WINDOWS                                    */
	/*                                                                              */
	/*                                                                              */
	//////////////////////////////////////////////////////////////////////////////////

	var openWinUoL = new Ext.Window({
		title: 'Open Learning Design',
		applyTo:'hello-win',
		width:410,
		height:238,
		closeAction:'hide',
		resizable:true,
		plain: true,
		items: gridUoL ,
		buttons: [{
			text:'Open',
			handler: function(){
				waitMsg: 'Loading...';
		var selModel = gridUoL.getSelectionModel();
		var record = selModel.selected.items[0].data.id;
		var title = selModel.selected.items[0].data.title;
		Ext.Ajax.request({
			url: 'configure/session.action',
			params: {
				id: record
			},
			success: function(response,options) 
			{ 
				var tab  = tabPanel.getActiveTab();
				var responseText = response.responseText;
				var array=responseText.split(",");
				var array2=array[2].split(":");
				tab.setTitle(array2[1]);
				Ext.getCmp('rolesTreeId').getStore().load();
			}
		});
		openWinUoL.hide();
			}

		},{
			text: 'Close',
			handler: function(){
				openWinUoL.hide();
			}
		}]
	});


	var openWin = new Ext.Window({
		title: 'Open Graphs',
		applyTo:'hello-win',
		//layout:'fit',
		width:410,
		height:238,
		closeAction:'hide',
		plain: true,
		items: grid ,
		buttons: [{
			text:'Open',
			handler: function(){
				waitMsg: 'Loading...';
		var selModel = grid.getSelectionModel();
		var record = selModel.selected.items[0].data.id;
		var code = selModel.selected.items[0].data.graphHtml;
		var parser=new DOMParser();
		var doc=parser.parseFromString(code,"text/xml");
		var pp = doc.documentElement.children;
		new deserializer_01.prototype.fromXML(pp, workflow);                	  
		openWin.hide();
			}

		},{
			text: 'Close',
			handler: function(){
				openWin.hide();
			}
		}]
	});

	var newRoleAttributeWin = new Ext.Window({
		//layout:'fit',
		width:520,
		height:500,
		closable: false,
		resizable: true,
		plain: true,
		border: false,
		title:'Edit Role Dialog',
		items:[RoleAttributeForm]
	});


	var newUoLWin = new Ext.Window({
		layout:'fit',
		width:300,
		height:230,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		title:'Create new Learning Design',
		items:[newUoLForm]
	});


	var newStaffRoleWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Staff Role',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newStaffRole]
	});


	var newLearnerRoleWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Learner Role',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newLearnerRole]
	});
	
	var learningActivityWin = new Ext.Window({
		title:'Edit Learning Activity Dialog'
		,width:400
		,height:300
		,plain:true
		,closable:false
		,layout:'fit'
		,layoutConfig:{animate:true}
		,border:false
		,items:[learningActivityForm]
		});


	//////////////////////////////////////////////////////////////////////////////////
	/*                         END  -  WINDOWS                                      */
	/*                                                                              */
	/*                                                                              */
	//////////////////////////////////////////////////////////////////////////////////


	var g = Ext.create('Ext.grid.PropertyGrid', {
		title: 'Property Grid',
		closable: true,
		source: {
			"Name": "",
			"Min Number of Persons": 0,
			"Max Number of Persons": 0,
			"productionQuality": false,
			"created": Ext.Date.parse('10/15/2006', 'd/m/Y'),
			"tested": false,
			"version": 0.01,
			"borderWidth": 1,
			"boss": true,
			"ActorId": 0
		}
	});
	var itemsPerPage = 100;
	var store = Ext.create('Ext.data.Store', {
		id:'simpsonsStore',
		autoLoad: true,
		fields:['id','graphHtml'],
		pageSize: itemsPerPage, // items per page
		proxy: {
			type: 'ajax',
			url: 'graph/view.action',  // url that will load data with respect to User and limit params
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});

	var grid = Ext.create('Ext.grid.Panel', {
		title: 'Graphs',
		store: store,
		columns: [
		          {header: 'Title',  dataIndex: 'id', flex:1}//,
		          ],
		          width: 400,
		          height: 175,
		          dockedItems: [{
		        	  xtype: 'pagingtoolbar',
		        	  store: store,   // same store GridPanel is using
		        	  dock: 'bottom',
		        	  displayInfo: true
		          }]//,         renderTo: Ext.getBody()
	}); 



	var storeUoL = Ext.create('Ext.data.Store', {
		id:'storeUoL',
		autoLoad: true,
		fields:['id','title','subject'],
		pageSize: itemsPerPage, // items per page
		proxy: {
			type: 'ajax',
			url: 'uol/view.action',  // url that will load data with respect to User and limit params
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});

	var gridUoL = Ext.create('Ext.grid.Panel', {
		title: 'Learning Design',
		store: storeUoL,
		resizable:true,
		columns: [
		          {header: 'Id',  dataIndex: 'id', flex:1},
		          {header: 'Title', dataIndex: 'title', flex:2},//
		          {header: 'Subject', dataIndex: 'subject', flex:3}
		          //{header: 'Phone', dataIndex: 'phone'}
		          ],
		          width: 400,
		          height: 175,
		          dockedItems: [{
		        	  xtype: 'pagingtoolbar',
		        	  store: storeUoL,   // same store GridPanel is using
		        	  dock: 'bottom',
		        	  displayInfo: true
		          }]//,         renderTo: Ext.getBody()
	}); 





	var tabPanel = Ext.create('Ext.tab.Panel', {
		region: 'center', // a center region is ALWAYS required for border layout
		id : 'center-panel',
		deferredRender: false,
		enableTabScroll: true,
		items: [{
			contentEl: 'center1',
			title: 'Learning Unit',
			autoScroll: true,
			autoHeight:true,
			autoWidth:true
		}]
	});
	


	var menuC = new Ext.menu.Menu({
		id: 'menuC', items: [
		                     { text: 'New Role' ,
		                    	 handler:function(index, event, rolesTree, node) {
		                    		 if( selectedNode == 1){
		                    			 newLearnerRoleWin.show();
		                    		 } else{
		                    			 newStaffRoleWin.show();
		                    		 }

		                    	 }}	 
		                     ]
	});


	var addonsStore = Ext.create('Ext.data.TreeStore', {
		proxy: {
			type: 'ajax',
			url: 'addons/getTreeaddons.action'
		},
		root: {
			text: 'Add-ons',
			id: 'root',
			expanded: true,
			children:[{
				text:'Text work',
				id: 'textwork',
				qtip:'Right click to create a new Text Work'
			},{
				text:'Uploading Files',
				id: 'uploadFiles',
				qtip:'Right click to create a new Uploading Files'
			}
			]
		}
	});
	
	var addonsTree = new  Ext.create('Ext.tree.TreePanel', {
		title: 'Add-ons',
		store: addonsStore,
		collapsible:true,
		width:200,
		layout:'fit',
		viewConfig: {
		forceFit:true
		},
		titleCollapse: true,
		id: 'addonsId',
		rootVisible: true,
		lines: false,
		dockedItems: [{
			xtype: 'toolbar',
			items: [{
				text: 'Expand All',
				handler: function(){
					addonsTree.expandAll();
				}
			}, {
				text: 'Collapse All',
				handler: function(){
					addonsTree.collapseAll();
				}
			}, {
				text: 'Refresh',
				handler: function(){
					Ext.getCmp('addonsId').getStore().load();

				}
			}]
		}]
	}); 
	
	
	var treeStore = Ext.create('Ext.data.TreeStore', {
		proxy: {
			type: 'ajax',
			url: 'role/getTreeRoles.action'
		},
		root: {
			text: 'Roles',
			id: 'root',
			expanded: true,
			children:[{
				text:'Learner',
				id: 'learnerLeaf',
				qtip:'Right click to create a new Learner Role'
			},{
				text:'Staff',
				id: 'staffLeaf',
				qtip:'Right click to create a new Staff Role'
			}
			]
		}
	});
	
	
	var rolesTree = new  Ext.create('Ext.tree.TreePanel', {
		title: 'Roles',
		store: treeStore,
		contentEl: 'west1',
		title: 'Learning Unit',
		autoScroll: true,
		autoHeight:true,
		autoWidth:true,
		collapsible:true,
		titleCollapse: true,
		id: 'rolesTreeId',
		rootVisible: true,
		width:200,
		layout:'fit',
		viewConfig: {
		forceFit:true
		},
		lines: false,
		viewConfig: {
			plugins: {
				ptype: 'treeviewdragdrop',
				appendOnly: true
			}
		},
		dockedItems: [{
			xtype: 'toolbar',
			items: [{
				text: 'Expand All',
				handler: function(){
					rolesTree.expandAll();
				}
			}, {
				text: 'Collapse All',
				handler: function(){
					rolesTree.collapseAll();
				}
			}, {
				text: 'Refresh',
				handler: function(){
					Ext.getCmp('rolesTreeId').getStore().load();

				}
			}]
		}],
		listeners: {
			dblclick: {
				element: 'body', //bind to the underlying body property on the panel
				fn: function(view, rec, node, index, e){ 
					if(rec.getText() != "Learner" && rec.getText() != "Staff" && rec.getText() != "Roles" ){
						roleToEdit = rec.getText();
						var form = RoleAttributeForm.getForm();
						Ext.Ajax.request({
							url: 'role/getAttributes.action',
							method: 'GET',
							params: {
								roleToEdit: roleToEdit
							},
							success: function(response, callOptions) 
							{ 
								var role = Ext.decode(response.responseText).role;
								var form = RoleAttributeForm.getForm();
								form.getFields().items[0].setValue(role.text);
								if(role.allowCreation == true){
									form.getFields().items[1].setValue(true);
									form.getFields().items[2].setValue(false);
								}else{
									form.getFields().items[1].setValue(false);
									form.getFields().items[2].setValue(true);
								}
								if(role.notAssignToOther == true){
									form.getFields().items[3].setValue(true);
									form.getFields().items[4].setValue(false);
								}else{
									form.getFields().items[3].setValue(false);
									form.getFields().items[4].setValue(true);
								}
								form.getFields().items[5].setValue(role.minPersons);
								form.getFields().items[6].setValue(role.maxPersons);
								if(role.information != null){
									form.getFields().items[7].setValue(role.information);
								}
							}
						});
						newRoleAttributeWin.show();
					}
				}
			},
			render: {
				fn: function() {
					// After the component has been rendered, disable the default browser context menu
					Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
				}
			},
			itemcontextmenu: {
				fn: function(view, rec, node, index, e){
					if(node.viewRecordId == "learnerLeaf" || node.viewRecordId == "staffLeaf"){
						selectedNode = index;
						menuC.showAt(e.getXY());
					}
				}
			}            	                       
		}
	}); 

	var tabPanel1 = Ext.create('Ext.tab.Panel', {
		region: 'west', // a center region is ALWAYS required for border layout
		id : 'west-panel',
		tabPosition: 'top',
		deferredRender: false,
		enableTabScroll: true,
		items: [rolesTree]
	});
	var toolBar = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [
		        {
		        	xtype: 'splitbutton',
		        	text : 'Learning Design',
		        	menu: [{
		        		text: 'New',
		        		id: 'FilenewItem',
		        		handler: function(){
		        			newUoLWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Open',
		        		id: 'FileopenItem',
		        		handler: function(){
		        			openWinUoL.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Save',
		        		id :'FilesaveItem',
		        		handler: function(){


		        			Ext.Ajax.request({
		        				url: 'graph/save.action',    // where you wanna post
		        				success:function() 
		        				{ 
		        					// Ext.Msg.alert('Boo', 'Success');
		        				},
		        				failure: function() 
		        				{ 
		        					//  Ext.Msg.alert('Boo', 'FAIL');
		        				},
		        				params: { htmlCode: new XMLSerializer_01().toXML(workflow) }  // your json data
		        			});
		        		}
		        	}]
		        },
		        {
		        	text: 'Button'
		        },

		        '->',
		        {
		        	xtype    : 'textfield',
		        	label    : "asd",
		        	fieldLabel: 'Search LD\'s',
		        	emptyText: 'enter search term'
		        }
		        ]
	});

	viewport = Ext.create('Ext.Viewport', {
		id: 'border-example',
		layout: 'border',
		items: [
		        // create instance immediately
		        toolBar
		        , {
		        	// lazily created panel (xtype:'panel' is default)
		        	region: 'south',
		        	id : 'south-panel',
		        	contentEl: 'south',
		        	split: true,
		        	height: 100,
		        	minSize: 100,
		        	maxSize: 200,
		        	collapsible: true,
		        	collapsed: true,
		        	title: 'South',
		        	margins: '0 0 0 0'
		        }, {
		        	xtype: 'tabpanel',
		        	id :'east-panel',
		        	region: 'east',
		        	disabled: false,
		        	title: 'East Side',
		        	dockedItems: [{
		        		dock: 'top',
		        		xtype: 'toolbar',
		        		items: [ '->', {
		        			xtype: 'button',
		        			text: 'test',
		        			tooltip: 'Test Button'
		        		}]
		        	}],
		        	animCollapse: true,
		        	collapsible: true,
		        	split: true,
		        	width: 225, // give east and west regions a width
		        	minSize: 175,
		        	maxSize: 400,
		        	margins: '0 5 0 0',
		        	activeTab: 1,
		        	tabPosition: 'bottom',
		        	items: [{
		        		html: '<p>A TabPanel component can be a region.</p>',
		        		title: 'A Tab',
		        		autoScroll: true
		        	}, g ]
		        }, tabPanel1,
		        tabPanel
		        ]
	});
	Ext.get("hideit").on('click', function(){
		var w = Ext.getCmp('west-panel');
		w.collapsed ? w.expand() : w.collapse();
	});
	var dragsource1=new Ext.dd.DragSource("activity", {ddGroup:'TreeDD',dragData:{name: Activity.prototype.type}}); 
	var dragsource2=new Ext.dd.DragSource("supportactivity", {ddGroup:'TreeDD',dragData:{name: SupportActivity.prototype.type}}); 
	var dragsource3=new Ext.dd.DragSource("start", {ddGroup:'TreeDD',dragData:{name: Start.prototype.type}}); 
	var dragsource4=new Ext.dd.DragSource("exit", {ddGroup:'TreeDD',dragData:{name: Exit.prototype.type}}); 
	var dragsource5=new Ext.dd.DragSource("OneToTwo", {ddGroup:'TreeDD',dragData:{name: OneToTwo.prototype.type}}); 
	var dragsource5=new Ext.dd.DragSource("TwoToOne", {ddGroup:'TreeDD',dragData:{name: TwoToOne.prototype.type}}); 
	var droptarget=new Ext.dd.DropTarget("center1",{ddGroup:'TreeDD'});

	droptarget.notifyDrop=function(dd, e, data)
	{
		var figuresSize = workflow.getFigures().size;
		if(data.name)
		{
			var xOffset    = workflow.getAbsoluteX();
			var yOffset    = workflow.getAbsoluteY();
			var scrollLeft = workflow.getScrollLeft();
			var scrollTop  = workflow.getScrollTop();

			figure = new Figure();

			workflow.addFigure(eval("new "+data.name+"()"),e.xy[0]-xOffset+scrollLeft,e.xy[1]-yOffset+scrollTop);
			return true;
		}
	}

	workflow.onMouseDown = function(x, y){

		var ob = workflow.getCurrentSelection();
		g.setSource({
			"Name": ob.type,
			"Min Number of Persons": 0,
			"Max Number of Persons": 0,
			"productionQuality": false,
			"created": Ext.Date.parse('10/15/2006', 'd/m/Y'),
			"tested": false,
			"version": 0.01,
			"borderWidth": 1,
			"boss": true,
			"ActorId": ob.getId()
		});
	}
	
	Activity.prototype.onDoubleClick=function(){
		alert(this.id);
		learningActivityWin.show();
};


});

//eof
